<template>
  <div class="JournalRankingContent">
    <div class="searchBox">
      <el-form ref="formRef" :model="sForm" class="demo-form-inline" label-position="right" label-width="100px">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="供应商名称">
                  <el-input v-clearEmoji v-model.trim="sForm.supplierName" clearable style="width: 70%;" placeholder="名称" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="供应商状态">
                  <el-select
                    v-model="sForm.status"
                    popper-class="eloption"
                    clearable
                    style="width: 70%;"
                    filterable
                    placeholder="请选择供应商状态"
                  >
                    <el-option v-for="(val,key) in scmStatusList" :key="key" :value="key" :label="val" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="查询时间">
                  <el-date-picker
                    v-model="date"
                    style="width: 70%;"
                    type="daterange"
                    unlink-panels
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="供应商类型">
                  <el-select
                    v-model="sForm.supplierType"
                    popper-class="eloption"
                    clearable
                    style="width: 70%;"
                    filterable
                    placeholder="请选择供应商类型"
                  >
                    <el-option v-for="(val,key) in scmTypeList" :key="key" :value="key" :label="val" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchFn" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="resetForm" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <!-- <div class="add" style="height: 30px;">
      <el-button style="background-color:#30B08F;color: #fff;" @click="addFn">新增</el-button>
    </div> -->
    <div class="table">
      <el-table border class="tablebox" :data="goodsList" style="width: 100%" size="medium">
        <el-table-column type="index" align="center" width="80" label="序号" />
        <el-table-column align="center" prop="name" label="供应商编号" />
        <el-table-column align="center" prop="name" label="供应商名称" />
        <el-table-column align="center" prop="name" label="供应商类型" />
        <el-table-column align="center" prop="name" label="联系人" />
        <el-table-column align="center" prop="name" label="省市区域" />
        <el-table-column align="center" prop="name" label="详细地址" />
        <el-table-column align="center" prop="name" label="流水金额（元）" />
        <el-table-column align="center" min-width="120" label="状态">
          <template v-slot="{row}">
            <el-tag v-if="row.productState === '0'" size="small" type="success">正常</el-tag>
            <el-tag v-if="row.productState === '1'" size="small" type="info">停用</el-tag>
            <el-tag v-if="row.productState === '2'" size="small" type="danger">淘汰</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :current-page="page.pageNum"
          :page-sizes="[3,5, 7,10]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getDictValueAndNameSource } from '@/api/dictionary'
export default {
  name: 'JournalRanking',
  data() {
    return {
      sForm: {
        status: '',
        supplierName: '',
        supplierType: ''
      },
      date: [],
      isSearch: false,
      goodsList: [],
      scmStatusList: {},
      scmTypeList: {},
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  computed: {
  },
  created() {
    this.getScmStatus()
    this.getScmType()
  },
  methods: {
    async getScmStatus() {
      const res = await getDictValueAndNameSource('SCM_STATUS')
      if (res.code === 200) {
        this.scmStatusList = res.data
      }
    },
    async getScmType() {
      const res = await getDictValueAndNameSource('SCM_TYPE')
      if (res.code === 200) {
        this.scmTypeList = res.data
      }
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val
      this.page.pageNum = 1
      console.log(`每页 ${val} 条`)
      // if (this.isSearch) {
      //   this.searchFn()
      // } else {
      //   this.getGoodsList()
      // }
    },
    // 获取页数改变
    handleCurrentChange(val) {
      this.page.pageNum = val
      // if (this.isSearch) {
      //   this.searchFn()
      // } else {
      //   this.getGoodsList()
      // }
    },
    resetForm() {
      // 重置
      this.isSearch = false
      console.log('reset', this.$refs.formRef)
      this.$refs.formRef.resetFields()
      this.sForm = {
        mnemonic: '',
        brand: '',
        categoryId: '',
        unitId: ''
      }
      this.page = {
        pageNum: 1,
        pageSize: 10,
        pages: 0,
        total: 0,
        endRow: 0
      }
      // this.getGoodsList()
    }
    // async searchFn() {
    //   if (!this.isSearch) {
    //     this.page = {
    //       pageNum: 1,
    //       pageSize: 10,
    //       pages: 0,
    //       total: 0,
    //       endRow: 0
    //     }
    //   }
    //   this.isSearch = true
    //   const res = await searchKeysGoodsList({ ...this.sForm, ...this.page })
    //   console.log({ ...this.sForm, ...this.page })
    //   if (res.code === 200) {
    //     const result = res.data
    //     console.log('sousuo', result)
    //     this.goodsList = result.list
    //     this.page.pageSize = result.pageSize
    //     this.page.pages = result.pages
    //     this.page.pageNum = result.pageNum
    //     this.page.total = result.total
    //     this.page.endRow = result.endRow
    //     console.log('搜索', this.goodsList)
    //   } else {
    //     // this.$message.error(res.message)
    //   }
    // }
  }
}
</script>

<style lang="scss" scoped>
.JournalRankingContent{
    padding: 10px;
    .searchBox{
        padding-top: 20px;
        background-color: #fff;
        margin-bottom: 10px;
    }
    .table{
        padding: 20px;
        background:#fff;
        .block{
          padding-top: 15px;
          text-align: center;
        }
    }
}
</style>
